/**
 * @file    IO_Config.h
 * @brief
 *
 * DAPLink Interface Firmware
 * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __IO_CONFIG_H__
#define __IO_CONFIG_H__

#include "stm32f10x.h"
#include "compiler.h"
#include "daplink.h"

COMPILER_ASSERT(DAPLINK_HIC_ID == DAPLINK_HIC_ID_STM32F103XB);

//USB control pin
#define USB_CONNECT_PORT_ENABLE()    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE)
#define USB_CONNECT_PORT_DISABLE()   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, DISABLE)
#define USB_CONNECT_PORT             GPIOA
#define USB_CONNECT_PIN              GPIO_Pin_15
#define USB_CONNECT_ON()             (USB_CONNECT_PORT->BSRR = USB_CONNECT_PIN)
#define USB_CONNECT_OFF()            (USB_CONNECT_PORT->BRR  = USB_CONNECT_PIN)



#define PIN_POWER_PORT             GPIOA
#define PIN_POWER_PIN              GPIO_Pin_4
#define PIN_POWER_Bit              4

// nRESET ISP
#define nRESET_ISP_PIN_PORT          GPIOB
#define nRESET_ISP_PIN               GPIO_Pin_8
#define nRESET_ISP_PIN_Bit           8

// nRESET BL
#define nRESET_BL_PIN_PORT          GPIOB
#define nRESET_BL_PIN               GPIO_Pin_7
#define nRESET_BL_PIN_Bit           7

// nRESET OUT Pin
#define nRESET_PIN_PORT              GPIOB
#define nRESET_PIN                   GPIO_Pin_9
#define nRESET_PIN_Bit               9

//SWD
#define SWCLK_TCK_PIN_PORT           GPIOB
#define SWCLK_TCK_PIN                GPIO_Pin_13
#define SWCLK_TCK_PIN_Bit            13

#define SWDIO_OUT_PIN_PORT           GPIOB
#define SWDIO_OUT_PIN                GPIO_Pin_14
#define SWDIO_OUT_PIN_Bit            14

#define SWDIO_IN_PIN_PORT            GPIOB
#define SWDIO_IN_PIN                 GPIO_Pin_12
#define SWDIO_IN_PIN_Bit             12

//LEDs
//USB status LED
#define RUNNING_LED_PORT             GPIOB
#define RUNNING_LED_PIN              GPIO_Pin_3
#define RUNNING_LED_Bit              3

//Connected LED
#define CONNECTED_LED_PORT           GPIOB
#define CONNECTED_LED_PIN            GPIO_Pin_3
#define CONNECTED_LED_PIN_Bit        3

#define PIN_HID_LED_PORT             GPIOB
#define PIN_HID_LED_PIN              GPIO_Pin_3
#define PIN_HID_LED_Bit              3

#define PIN_CDC_LED_PORT             GPIOB
#define PIN_CDC_LED_PIN              GPIO_Pin_4
#define PIN_CDC_LED_Bit              4

#define PIN_MSC_LED_PORT             GPIOB
#define PIN_MSC_LED_PIN              GPIO_Pin_5
#define PIN_MSC_LED_Bit              5


#endif
